package com.xianguo.app1;

import java.text.SimpleDateFormat;
import java.util.Date;

import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class DateAct extends Activity implements OnClickListener {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.date_act);
        
        Button btnShowDate = (Button)findViewById(R.id.btnShowDate);
        Button btnShowTime = (Button)findViewById(R.id.btnShowTime);
        btnShowDate.setOnClickListener(this);
        btnShowTime.setOnClickListener(this);
    }

	@Override
	public void onClick(View v) {
		switch(v.getId()){
		case R.id.btnShowDate:
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			showDialog("显示日期",sdf.format(new Date()));
			break;
		case R.id.btnShowTime:
			SimpleDateFormat sdf1 = new SimpleDateFormat("HH:mm:ss");
			showDialog("显示时间",sdf1.format(new Date()));
			break;
		}
		
	}
	
	private void showDialog(String title,String msg){
		AlertDialog.Builder builder = new AlertDialog.Builder(this);
		builder.setIcon(android.R.drawable.ic_dialog_info);
		builder.setTitle(title);
		builder.setMessage(msg);
		builder.setPositiveButton("OK", null);
		builder.create().show();
	}
}
